<%--
  Created by IntelliJ IDEA.
  User: Administrator
  Date: 2021/6/21
  Time: 18:55
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
    <form action="AddServlet" method="post">
        <table border="1">
            <input type="hidden" id="a">
            <tr>
                <td colspan="2">
                    <h2>添加疫苗接种预约信息</h2>
                </td>
            </tr>
            <tr>
                <td>预约人姓名(*)</td>
                <td><input type="text" name="userName" id="userName"/></td>
            </tr>
            <tr>
                <td>预约人身份证号(*)</td>
                <td><input type="text" name="cardId" id="cardId" onblur="s()"/><p id="w"></p></td>
            </tr>
            <tr>
                <td>预约接种日期(*)</td>
                <td>
                    <input type="text" name="bookingDate" id="bookingDate"/><br>
                </td>
            </tr>
            <tr>
                <td colspan="2" align="center">
                    <input type="submit" value="提交" id="sub"/>
                </td>
            </tr>
        </table>
    </form>
    <script src="js/jquery-1.8.3.min.js"></script>
    <script type="text/javascript">
        function s(){
            var cardId = $("#cardId").val();
            $.getJSON('CardIdServlet','cardId='+cardId,function (date){
                alert(date) ;
                $("#w").html(date);
                if(date!=""){
                    $("#a").val("1");
                }else{
                    $("#a").val("");
                }
            })
        }

        $("form").submit(function(){
            var userName = $("#userName").val();
            var cardId = $("#cardId").val();
            if(userName=="" || userName==null){
                alert("请填写完整的预约信息!");
                return false;
            }
            if(cardId == "" ||cardId==null ){
                alert("请填写完整的预约信息!");
                return false;
            }
            var date = /^(\d{4})-(\d{2})-(\d{2})$/;
            var bookingDate = $("#bookingDate").val();
            if(date.test(bookingDate)==false){
                alert("日期格式不正确!");
                return false;
            }
            return true;
        })
    </script>
</body>
</html>
